
#---------------------主界面展示---------------------------
def show():
    print('*'*40)
    print(' '*18+'银行存取款系统'+' ')
    print('='*26)
    print('{0}{1:^20}{2}{3:^20}{4}'.format('|','1.用户注册','|','2.用户登录','|'))
    print('='*26)
    print('{0}{1:^20}{2}{3:^20}{4}'.format('|','3.用户注销','|','4.用户取卡','|'))
    print('='*26)
    rst = input('请输入对应选项(输入对应数字)：')
    print('*'*40)
    return rst #返回主界面操作数值
#-----------------------------------------------------------------------------

#------------------------------用户注册-----------------------------------
def user_reg():
    print('*'*40)
    print(' '*18+'用户注册页面'+' ')
    print('='*26)
    name = input('请输出用户名：')
    passwd1 = input('请输入密码：')
    passwd2 = input('请再次输入密码：')
    while True:
        if (passwd1 == passwd2):
            user[name] = passwd1
            user_money[name] = 0.00  #用户金额默认为零
            break
        else:
            passwd1 = input('请重新输入密码：')
            passwd2 = input('请再次输入密码：')
#------------------------------------------------------------


#------------------------用户登陆---------------------------
def user_login():
    while True:
        print('*'*40)
        print(' '*18+'用户登陆页面'+' ')
        print('='*26)
        name = input('请输入用户名:')
        passwd = input('请输入密码:')
        try:
            if (user[name] == passwd):
                return name
            else:
                print('*'*40)
                print('密码错误!')
        except KeyError:
            print('*'*40)
            print('无此用户!')
            return 3
#----------------------------------------------------------

#--------------------------用户信息-----------------------
def user_msg(name):
        print('*'*40)
        print(' '*18+'用户信息'+' ')
        print('='*26)
        print('{0}{1:^22}{2}{3:^20}{4}'.format('|','用户名称','|',name,'|'))
        print('='*26)
        print('{0}{1:^20}{2:10}{3:^.2f}{4:>8}'.format('|','账户余额￥','|',user_money[name],'元|'))
        print('='*26)
        print('{0}{1:^12}{2}{3:^12}{4}{5:^12}{6}'.format('|','1.用户取款','|','2.用户存款','|','3.取消返回','|'))
        rst1 = input('请输入对应选项(输入对应数字)：')
        print('*'*40)
        return rst1 #返回操作数值
#---------------------------------------------------------------------------------------

#----------------------用户操作-------------------------------------------
def user_do(name,rst):
        if (rst == 1):
            get_money = float(input('请输入取款金额:'))
            money = float(user_money[name])-get_money
            if (money < 0):
                print('*'*40)
                print('你的余额不足,请重新输入!')
            else:
                user_money[name] = money
        elif (rst == 2):
            post_money = float(input('请输入存款金额:'))
            money = float(user_money[name])+post_money
            user_money[name] = money
#-----------------------------------------------------------------

#------------------用户注销-------------------------
def user_del(name):
    while True:
        a = input('确认注销此账户(YES/NO):')
        if (a == 'YES' or a == 'y' or a == 'yes'):
            if (user_money[name] == 0):
                del user[name]
                del user_money[name]
                print('*'*40)
                print('账户已注销,感谢使用!')
                break
            else:
                print('*'*40)
                print('请取出所有存款后再注销账户!')
                rst2 = int(user_msg(name))
                user_do(name,rst2)
#-----------------------------------------------------------
        

#---------主程序-------------------------
def main():
    while True:
        rst = int(show())
        if (rst == 1):
            user_reg() #注册账户
        elif (rst == 2):
            name = user_login()
            while (name != 3):#若无此用户名则跳出登陆循环
                rst1 = int(user_msg(name))
                if (rst1 == 3): 
                    break
                else:
                    user_do(name,rst1)
        elif  (rst == 3):
            name = user_login()
            user_del(name)  
        elif (rst == 4):
            print('感谢使用!')
            break
        else:
            print('输入无效操作!')
#----------------------------------------------------           
#主程序运行
user = {}  #用户名和用户密码
user_money = {}   #用户名和用户金额
main()
